package com.chixing.day02;

import java.util.Arrays;

/**
 * @author Y2014188432
 */
public class MyContainer {
    public static int[] arr;
    public static int mark = 0;
    public static int step = 10;

    public MyContainer(){
        arr = new int[5];
    }

    /**
     * 带参构造
     * @param size 初始大小
     * @param increment 增量
     */
    public MyContainer(int size,int increment){
        arr = new int[size];
        step = increment;
    }

    /**
     * 添加数据
     * @param param 所要添加的数据
     */
    public void add(int param){
        if(mark == arr.length){
            expansion();
        }
        arr[mark ++] = param;
    }

    public void add(int param, int index){
        if(mark == arr.length){
            expansion();
        }
        for (int i = mark; i >= index ; i--) {
            arr[i] = arr[i - 1];
        }
        arr[index - 1] = param;
        mark ++;
    }
    /**
     * 展示数组
     */
    public void display(){
        for (int i = 0; i < mark; i++) {
            System.out.print(arr[i]+" ");
        }
    }

    /**
     * 扩容
     * 扩容后为 : 原大小 + step
     */
    public void expansion(){
        arr = Arrays.copyOf(arr,arr.length + step);
    }
}
